package com.zch.work.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zch.domain.Result;
import com.zch.entity.TbMould;
import com.zch.entity.TbOperateMould;
import com.zch.handler.ResponseHandler;
import com.zch.utils.ExcelUtils;
import com.zch.work.service.TbMouldService;
import com.zch.work.mapper.TbMouldMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* @author 28763
* @description 针对表【tb_mould(设备/工装/模具维护表)】的数据库操作Service实现
* @createDate 2023-10-30 19:57:14
*/
@Service
public class TbMouldServiceImpl extends ServiceImpl<TbMouldMapper, TbMould>
    implements TbMouldService{

    @Override
    public Result deletedByID(TbMould tbMould) {
        TbMould mould = new TbMould();
        mould.setId(tbMould.getId());
        mould.setDeleted(1);
        boolean b = updateById(mould);
        return b?Result.SUCCESS():Result.FAILED(201,"删除失败");
    }

    @Override
    public Result addOperate(TbMould tbMould) {
        boolean save = save(tbMould);
        return save?Result.SUCCESS():Result.FAILED(201,"添加失败");
    }

    @Override
    public Result updateAll(TbMould tbMould) {
        boolean b = updateById(tbMould);
        return b?Result.SUCCESS():Result.FAILED(201,"修改失败");
    }

    @Override
    public void exports(HttpServletResponse response) {
        List<TbMould> list = list();
        ExcelUtils.export(response,"设备/工装/模具名称维护表",list,TbMould.class);
    }

    @Override
    public Result importJob(MultipartFile file) throws Exception {
        List<TbMould> tbMoulds = ExcelUtils.readMultipartFile(file, TbMould.class);
        for (TbMould tbMould : tbMoulds) {
            save(tbMould);
        }
        return Result.SUCCESS();
    }
}




